#include "KTicker.h"
#include "KDebug.h"

KTicker::KTicker()
{
    m_freq.QuadPart = m_beg.QuadPart = 0;
    if (QueryPerformanceFrequency(&m_freq)) {
        reset();
    } else {
        KDebugLib("QueryPerformanceFrequency() failed: %d", GetLastError());
    }
}

double KTicker::elapsed() const
{
    LARGE_INTEGER cur;
    if (!QueryPerformanceCounter(&cur)) {
        KDebugLib("QueryPerformanceCounter() failed: %d", GetLastError());
        return 0.0;
    }
    return double(cur.QuadPart - m_beg.QuadPart) / m_freq.QuadPart;
}

void KTicker::reset()
{
    if (!QueryPerformanceCounter(&m_beg)) {
        KDebugLib("QueryPerformanceCounter() failed: %d", GetLastError());
    }
}